﻿using System;
using System.Net;

class FileDownloading
{
    static void Main()
    {
        //Exercise 4.
        //Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg) and stores it 
        //the current directory. Find in Google how to download files in C#. Be sure to catch all exceptions and 
        //to free any used resources in the finally block.

        using (WebClient client = new WebClient())
        { 
            try
            {
                client.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", @"C:\Users\Toni\Desktop\myfile.jpg");
            }
            catch (WebException wEx)
            {
                Console.WriteLine(wEx.Message);
                Console.WriteLine("The address is invalid.");
            }
            catch (NotSupportedException nSE)
            {
                Console.WriteLine(nSE.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
            
    }
}

